﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace Kooboo.CMS.CustomSettingSyncWrapper
{
    public class SiteSettingsActionAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (IsSiteSettingPage(filterContext))
            {
                var response = filterContext.HttpContext.Response;
                response.Filter = new CustomResponseFilter(response.Filter);
            }

            base.OnActionExecuted(filterContext);
        }

        private bool IsSiteSettingPage(ActionExecutedContext filterContext)
        {
            var request = filterContext.HttpContext.Request;

            return request.Url.PathAndQuery.StartsWith("/sites/system", StringComparison.InvariantCultureIgnoreCase)
                && request.HttpMethod.Equals("get", StringComparison.InvariantCultureIgnoreCase);
        }
    }
}
